<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveSupport::CoreExtensions::String::Inflections</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveSupport::CoreExtensions::String::Inflections</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/vendor/rails/activesupport/lib/active_support/core_ext/string/inflections_rb.html">
                vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
String inflections define new methods on the String class to transform
names for different purposes. For instance, you can figure out the name of
a database from the name of a class.
</p>
<pre>
  &quot;ScaleScore&quot;.tableize =&gt; &quot;scale_scores&quot;
</pre>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000743">camelcase</a>&nbsp;&nbsp;
      <a href="#M000742">camelize</a>&nbsp;&nbsp;
      <a href="#M000750">classify</a>&nbsp;&nbsp;
      <a href="#M000753">constantize</a>&nbsp;&nbsp;
      <a href="#M000747">dasherize</a>&nbsp;&nbsp;
      <a href="#M000748">demodulize</a>&nbsp;&nbsp;
      <a href="#M000752">foreign_key</a>&nbsp;&nbsp;
      <a href="#M000751">humanize</a>&nbsp;&nbsp;
      <a href="#M000740">pluralize</a>&nbsp;&nbsp;
      <a href="#M000741">singularize</a>&nbsp;&nbsp;
      <a href="#M000749">tableize</a>&nbsp;&nbsp;
      <a href="#M000745">titlecase</a>&nbsp;&nbsp;
      <a href="#M000744">titleize</a>&nbsp;&nbsp;
      <a href="#M000746">underscore</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000743" class="method-detail">
        <a name="M000743"></a>

        <div class="method-heading">
          <span class="method-name">camelcase</span><span class="method-args">(first_letter = :upper)</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="Inflections.html#M000742">camelize</a>
</p>
        </div>
      </div>

      <div id="method-M000742" class="method-detail">
        <a name="M000742"></a>

        <div class="method-heading">
          <a href="#M000742" class="method-signature">
          <span class="method-name">camelize</span><span class="method-args">(first_letter = :upper)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
By default, <a href="Inflections.html#M000742">camelize</a> converts
strings to UpperCamelCase. If the argument to <a
href="Inflections.html#M000742">camelize</a> is set to &quot;:lower&quot;
then <a href="Inflections.html#M000742">camelize</a> produces
lowerCamelCase.
</p>
<p>
<a href="Inflections.html#M000742">camelize</a> will also convert
&#8217;/&#8217; to &#8217;::&#8217; which is useful for converting paths to
namespaces
</p>
<p>
Examples
</p>
<pre>
  &quot;active_record&quot;.camelize #=&gt; &quot;ActiveRecord&quot;
  &quot;active_record&quot;.camelize(:lower) #=&gt; &quot;activeRecord&quot;
  &quot;active_record/errors&quot;.camelize #=&gt; &quot;ActiveRecord::Errors&quot;
  &quot;active_record/errors&quot;.camelize(:lower) #=&gt; &quot;activeRecord::Errors&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000742-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000742-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb, line 46</span>
46:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">camelize</span>(<span class="ruby-identifier">first_letter</span> = <span class="ruby-identifier">:upper</span>)
47:           <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">first_letter</span>
48:             <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:upper</span> <span class="ruby-keyword kw">then</span> <span class="ruby-constant">Inflector</span>.<span class="ruby-identifier">camelize</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-keyword kw">true</span>)
49:             <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:lower</span> <span class="ruby-keyword kw">then</span> <span class="ruby-constant">Inflector</span>.<span class="ruby-identifier">camelize</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-keyword kw">false</span>)
50:           <span class="ruby-keyword kw">end</span>
51:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000750" class="method-detail">
        <a name="M000750"></a>

        <div class="method-heading">
          <a href="#M000750" class="method-signature">
          <span class="method-name">classify</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Create a class name from a table name like <a
href="../../../Rails.html">Rails</a> does for table names to models. Note
that this returns a string and not a Class. (To convert to an actual class
follow <a href="Inflections.html#M000750">classify</a> with <a
href="Inflections.html#M000753">constantize</a>.)
</p>
<p>
Examples
</p>
<pre>
  &quot;egg_and_hams&quot;.classify #=&gt; &quot;EggAndHam&quot;
  &quot;post&quot;.classify #=&gt; &quot;Post&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000750-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000750-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb, line 114</span>
114:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">classify</span>
115:           <span class="ruby-constant">Inflector</span>.<span class="ruby-identifier">classify</span>(<span class="ruby-keyword kw">self</span>)
116:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000753" class="method-detail">
        <a name="M000753"></a>

        <div class="method-heading">
          <a href="#M000753" class="method-signature">
          <span class="method-name">constantize</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Constantize tries to find a declared constant with the name specified in
the string. It raises a NameError when the name is not in CamelCase or is
not initialized.
</p>
<p>
Examples
</p>
<pre>
  &quot;Module&quot;.constantize #=&gt; Module
  &quot;Class&quot;.constantize #=&gt; Class
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000753-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000753-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb, line 147</span>
147:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">constantize</span>
148:           <span class="ruby-constant">Inflector</span>.<span class="ruby-identifier">constantize</span>(<span class="ruby-keyword kw">self</span>)
149:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000747" class="method-detail">
        <a name="M000747"></a>

        <div class="method-heading">
          <a href="#M000747" class="method-signature">
          <span class="method-name">dasherize</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Replaces underscores with dashes in the string.
</p>
<p>
Example
</p>
<pre>
  &quot;puni_puni&quot; #=&gt; &quot;puni-puni&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000747-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000747-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb, line 83</span>
83:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dasherize</span>
84:           <span class="ruby-constant">Inflector</span>.<span class="ruby-identifier">dasherize</span>(<span class="ruby-keyword kw">self</span>)
85:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000748" class="method-detail">
        <a name="M000748"></a>

        <div class="method-heading">
          <a href="#M000748" class="method-signature">
          <span class="method-name">demodulize</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Removes the module part from the expression in the string
</p>
<p>
Examples
</p>
<pre>
  &quot;ActiveRecord::CoreExtensions::String::Inflections&quot;.demodulize #=&gt; &quot;Inflections&quot;
  &quot;Inflections&quot;.demodulize #=&gt; &quot;Inflections&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000748-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000748-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb, line 92</span>
92:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">demodulize</span>
93:           <span class="ruby-constant">Inflector</span>.<span class="ruby-identifier">demodulize</span>(<span class="ruby-keyword kw">self</span>)
94:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000752" class="method-detail">
        <a name="M000752"></a>

        <div class="method-heading">
          <a href="#M000752" class="method-signature">
          <span class="method-name">foreign_key</span><span class="method-args">(separate_class_name_and_id_with_underscore = true)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates a foreign key name from a class name.
<tt>separate_class_name_and_id_with_underscore</tt> sets whether the method
should put &#8216;_&#8217; between the name and &#8216;id&#8217;.
</p>
<p>
Examples
</p>
<pre>
  &quot;Message&quot;.foreign_key #=&gt; &quot;message_id&quot;
  &quot;Message&quot;.foreign_key(false) #=&gt; &quot;messageid&quot;
  &quot;Admin::Post&quot;.foreign_key #=&gt; &quot;post_id&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000752-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000752-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb, line 136</span>
136:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">foreign_key</span>(<span class="ruby-identifier">separate_class_name_and_id_with_underscore</span> = <span class="ruby-keyword kw">true</span>)
137:           <span class="ruby-constant">Inflector</span>.<span class="ruby-identifier">foreign_key</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">separate_class_name_and_id_with_underscore</span>)
138:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000751" class="method-detail">
        <a name="M000751"></a>

        <div class="method-heading">
          <a href="#M000751" class="method-signature">
          <span class="method-name">humanize</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Capitalizes the first word and turns underscores into spaces and strips
_id. Like <a href="Inflections.html#M000744">titleize</a>, this is meant
for creating pretty output.
</p>
<p>
Examples
</p>
<pre>
  &quot;employee_salary&quot; #=&gt; &quot;Employee salary&quot;
  &quot;author_id&quot; #=&gt; &quot;Author&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000751-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000751-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb, line 124</span>
124:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">humanize</span>
125:           <span class="ruby-constant">Inflector</span>.<span class="ruby-identifier">humanize</span>(<span class="ruby-keyword kw">self</span>)
126:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000740" class="method-detail">
        <a name="M000740"></a>

        <div class="method-heading">
          <a href="#M000740" class="method-signature">
          <span class="method-name">pluralize</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the plural form of the word in the string.
</p>
<p>
Examples
</p>
<pre>
  &quot;post&quot;.pluralize #=&gt; &quot;posts&quot;
  &quot;octopus&quot;.pluralize #=&gt; &quot;octopi&quot;
  &quot;sheep&quot;.pluralize #=&gt; &quot;sheep&quot;
  &quot;words&quot;.pluralize #=&gt; &quot;words&quot;
  &quot;the blue mailman&quot;.pluralize #=&gt; &quot;the blue mailmen&quot;
  &quot;CamelOctopus&quot;.pluralize #=&gt; &quot;CamelOctopi&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000740-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000740-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb, line 19</span>
19:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pluralize</span>
20:           <span class="ruby-constant">Inflector</span>.<span class="ruby-identifier">pluralize</span>(<span class="ruby-keyword kw">self</span>)
21:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000741" class="method-detail">
        <a name="M000741"></a>

        <div class="method-heading">
          <a href="#M000741" class="method-signature">
          <span class="method-name">singularize</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The reverse of <a href="Inflections.html#M000740">pluralize</a>, returns
the singular form of a word in a string.
</p>
<p>
Examples
</p>
<pre>
  &quot;posts&quot;.singularize #=&gt; &quot;post&quot;
  &quot;octopi&quot;.singularize #=&gt; &quot;octopus&quot;
  &quot;sheep&quot;.singluarize #=&gt; &quot;sheep&quot;
  &quot;word&quot;.singluarize #=&gt; &quot;word&quot;
  &quot;the blue mailmen&quot;.singularize #=&gt; &quot;the blue mailman&quot;
  &quot;CamelOctopi&quot;.singularize #=&gt; &quot;CamelOctopus&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000741-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000741-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb, line 32</span>
32:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">singularize</span>
33:           <span class="ruby-constant">Inflector</span>.<span class="ruby-identifier">singularize</span>(<span class="ruby-keyword kw">self</span>)
34:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000749" class="method-detail">
        <a name="M000749"></a>

        <div class="method-heading">
          <a href="#M000749" class="method-signature">
          <span class="method-name">tableize</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Create the name of a table like <a href="../../../Rails.html">Rails</a>
does for models to table names. This method uses the <a
href="Inflections.html#M000740">pluralize</a> method on the last word in
the string.
</p>
<p>
Examples
</p>
<pre>
  &quot;RawScaledScorer&quot;.tableize #=&gt; &quot;raw_scaled_scorers&quot;
  &quot;egg_and_ham&quot;.tableize #=&gt; &quot;egg_and_hams&quot;
  &quot;fancyCategory&quot;.tableize #=&gt; &quot;fancy_categories&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000749-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000749-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb, line 103</span>
103:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">tableize</span>
104:           <span class="ruby-constant">Inflector</span>.<span class="ruby-identifier">tableize</span>(<span class="ruby-keyword kw">self</span>)
105:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000745" class="method-detail">
        <a name="M000745"></a>

        <div class="method-heading">
          <span class="method-name">titlecase</span><span class="method-args">()</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="Inflections.html#M000744">titleize</a>
</p>
        </div>
      </div>

      <div id="method-M000744" class="method-detail">
        <a name="M000744"></a>

        <div class="method-heading">
          <a href="#M000744" class="method-signature">
          <span class="method-name">titleize</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Capitalizes all the words and replaces some characters in the string to
create a nicer looking title. Titleize is meant for creating pretty output.
It is not used in the <a href="../../../Rails.html">Rails</a> internals.
</p>
<p>
<a href="Inflections.html#M000744">titleize</a> is also aliased as as <a
href="Inflections.html#M000745">titlecase</a>
</p>
<p>
Examples
</p>
<pre>
  &quot;man from the boondocks&quot;.titleize #=&gt; &quot;Man From The Boondocks&quot;
  &quot;x-men: the last stand&quot;.titleize #=&gt; &quot;X Men: The Last Stand&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000744-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000744-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb, line 63</span>
63:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">titleize</span>
64:           <span class="ruby-constant">Inflector</span>.<span class="ruby-identifier">titleize</span>(<span class="ruby-keyword kw">self</span>)
65:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000746" class="method-detail">
        <a name="M000746"></a>

        <div class="method-heading">
          <a href="#M000746" class="method-signature">
          <span class="method-name">underscore</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The reverse of <tt><a href="Inflections.html#M000742">camelize</a></tt>.
Makes an underscored form from the expression in the string.
</p>
<p>
Changes &#8217;::&#8217; to &#8217;/&#8217; to convert namespaces to paths.
</p>
<p>
Examples
</p>
<pre>
  &quot;ActiveRecord&quot;.underscore #=&gt; &quot;active_record&quot;
  &quot;ActiveRecord::Errors&quot;.underscore #=&gt; active_record/errors
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000746-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000746-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb, line 75</span>
75:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">underscore</span>
76:           <span class="ruby-constant">Inflector</span>.<span class="ruby-identifier">underscore</span>(<span class="ruby-keyword kw">self</span>)
77:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>